<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:composite="http://java.sun.com/jsf/composite">

    <h:head>
        <f:facet name="first">
            <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
        </f:facet>
    </h:head>

    <composite:interface>
        <composite:attribute name="lblbtnfind" type="java.lang.String" />
        <composite:attribute name="update" type="java.lang.String" />
    </composite:interface>

    <composite:implementation>

        <p:outputPanel>
            <p:commandButton id="btnFindProveedor" value="#{cc.attrs.lblbtnfind}"
                             icon="ui-icon-search" immediate="true" update="pnlFindProveedor" process="@this" ajax="true"
                             actionListener="#{MBComponenteFindProveedor.inicializarBusqueda}"
                             oncomplete="wv#{cc.id}.show()" style="font-size:10px;">
            </p:commandButton>	
        </p:outputPanel>

        <p:dialog id="idFindProveedor" header="Buscando Proveedor" showEffect="explode"
                  widgetVar="wv#{cc.id}" modal="true" maximizable="true">
            <p:messages id="growl" showDetail="true" autoUpdate="false" rendered="false"/>
            <p:panelGrid id="pnlFindProveedor" style="width:100%;text-align:left">
                <p:row>
                    <p:column>
                        <h:outputLabel id="lblRazon" value="RAZÓN SOCIAL: " class="lblForm" />
                    </p:column>
                    <p:column>
                        <p:inputText id="txtRazonBuscar"  onkeyup="cambiarMayuscula(this)" value="#{BKComponenteFindProveedor.razon}" size="80"/>
                    </p:column>
                    <p:column>
                        <p:commandButton id="btnFindBuscar" value="Buscar" 
                                         ajax="true" update="datatblProveedores,growl" process="@this txtRazonBuscar" 
                                         actionListener="#{MBComponenteFindProveedor.buscarProveedores()}"/>
                    </p:column>
                    <p:column>
                        <p:commandButton id="btnNuevoProveedor" action="#{MBProveedor.nuevo()}" value="AGREGAR PROVEEDOR" ajax="false" 
                                         onclick="wv#{cc.id}.hide();"/>
                    </p:column>

                </p:row>

                <p:row>
                    <p:column colspan="4">
                        <p:fieldset legend="Lista de Proveedores">
                            <p:dataTable id="datatblProveedores" var="proveedor"
                                         value="#{BKComponenteFindProveedor.listaProveedors}"
                                         emptyMessage="No exsiten proveedores" filteredValue=""
                                         rowIndexVar="rowIndex" paginator="true" rows="10"
                                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink}
                                         {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                         rowsPerPageTemplate="10,20,30"  rowKey="#{proveedor.id}"  
                                         selection="#{BKComponenteFindProveedor.proveedorSeleccionado}" selectionMode="single"
                                         paginatorPosition="bottom" styleClass="datable-busqueda" style="height: 270px">

                                <p:ajax event="rowSelect"/>

                                <p:column id="idColumnaNum" style="width: 5%" headerText="N°.">
                                    <h:outputText value="#{rowIndex+1}" />
                                </p:column>

                                <p:column id="idColumnaRUC" style="width: 15%"
                                          sortBy="#{proveedor.ruc}" 
                                          headerText="RUC">
                                    <h:outputText value="#{proveedor.ruc}" />
                                </p:column>

                                <p:column id="idColumnaRazon" style="width: 80%"
                                          sortBy="#{proveedor.razonSocial}"  headerText="Razon Social">
                                    <h:outputText value="#{proveedor.razonSocial}" />
                                </p:column>

                            </p:dataTable>
                        </p:fieldset>
                    </p:column>
                </p:row>
                <p:row>
                    <p:column style="text-align:center" colspan="3">
                        <p:commandButton id="btnAceptarProveedor" value="Aceptar"
                                         actionListener="#{MBComponenteFindProveedor.notificarObservadores()}"
                                         process="@this pnlFindProveedor" update="#{cc.attrs.update}"      
                                         oncomplete="if (args.validationFailed){ wv#{cc.id}.show()} else {wv#{cc.id}.hide()}" />
                        <p:commandButton id="btnCancelarProveedor" value="Cancelar" type="button"
                                         onclick="wv#{cc.id}.hide();" />
                    </p:column>
                </p:row>
            </p:panelGrid>
        </p:dialog>

    </composite:implementation>

</html>